<?php
class Controller{
    private static $instance;
	
	protected $conf=null;
    //public $db=null;
	protected $template=null;
    
	public function __construct(){
        self::$instance =& $this;
		$this->conf=VG::$config;
        //$model=new Model();
		// $this->db=$model->getConnection();
		//$this->db=$model->getLink();
		
		// 设置模板引擎参数
		$config = [
			'view_path'	=>	APPPATH.'views/',
			'cache_path'	=>	'./runtime/tpl_cache/',
			'view_suffix'   =>	'html',
		];

		$this->template = new \think\Template($config);
	}
    public static function &get_instance(){
		return self::$instance;
	}
	
	public function tpl($var,$tpl_path=''){
		$f=APPPATH.'views/'.($tpl_path?$tpl_path:(VG::$module.'/'.VG::$control.'/'.VG::$action)).'.html';
		if(!file_exists($f)){
			exit("template not exists:".$f);
		}
		$var=array_merge($var,$this->template->get());
		$this->template->fetch($tpl_path?$tpl_path:VG::$module.'/'.VG::$control.'/'.VG::$action,$var);
	}
	public function fetch($tpl,$var){
        $var=array_merge($var,$this->template->get());
        $this->template->fetch($tpl,$var);
    }

//
}